package android.musicplayer.home;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListSong extends Activity {
	
	private ListView listView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		listView = new ListView(ListSong.this);
		listView.setAdapter(new ArrayAdapter<String>(ListSong.this, android.R.layout.simple_expandable_list_item_1, getData()));
		setContentView(listView);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
					setTitle(arg2);
			}
		});
	}
	
	private List<String> getData(){
		List<String> data = new ArrayList<String>();
		Cursor cursor = getContentResolver().query(  
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null,  
                MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
		while(cursor.moveToNext()){
			String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
			data.add(title);
		}
		
		return data;
	}
	
	
}
